  /*
	@Author: 于辉
	@Time: 2020-11
	@Tittle: rolePowers
	@Description: 用户详情
*/
var form;
layui.use(['form'], function(){
  form = layui.form
  ,layer = layui.layer
  var index = parent.layer.getFrameIndex(window.name); 
  
  form.render();
  //自定义验证规则
  form.verify({
    userName: function(value){
      if(value.length < 4){
        return '用户名至少得4个字符啊';
      }
      
    }
    ,nickName:function(value) {
          if (value.length < 4) {
              return '昵称至少得4个字符啊';
          }
      }
    ,password: [
      /^[\S]{6,20}$/
      ,'密码必须6到20位，且不能出现空格'
    ],
    myphone:function(value){
    	if(value != ""){
    		var exp = /^1[0-9]{10}$/;
		    if (value && !exp.test(value)) {
		        return '请输入正确的手机';
		    }
    	}
    }
  });
  
  $("#btn_cancle").click(function () {
      parent.layer.close(index);
  })
  form.on('submit(btn_save)', function(data){
		data = data.field;
	    data.enabled = data.enabled=='on'?true:false;
		var serverpath = getServerPath("CREATEUSER");
		if($("#userID").val() != ''){
			serverpath = getServerPath("UPDATEUSER");
		}
		ajaxSetting({
			url:serverpath,
			data:JSON.stringify(data),
			async:false,
			success:function(res){
				layer.msg("保存成功",{icon:6})
				parent.reloadTable();
				setTimeout(function(){
					parent.layer.close(index);
				},500)
				
			},
			error:function(res){
				console.log(res)
			}
		})
		return false;
	});
 });
 
function initData(userid){
	console.log(userid)
	ajaxSetting({
		url:getServerPath("GETUSERMODEL")+"?id="+userid,
		type:"get",
		success:function(res){
			console.log(res)
			form.val('userinfo', res.data);
			$("#pan_password").remove();
		}
	})
}
